 //
//  EyeButton.m
//  CarCare
//
//  Created by ileo on 14-8-31.
//  Copyright (c) 2014年 baozun. All rights reserved.
//

#import "EyeButton.h"
#import "ImageHelper.h"

@interface EyeButton()

@property (nonatomic, strong) UITextField *textField;

@end

@implementation EyeButton

- (id)initWithTextField:(UITextField *)textField
{
    self = [super initWithFrame:CGRectMake(0, 0, 46, 30)];
    if (self) {
        // Initialization code
        
        self.textField = textField;
        
        self.center = CGPointMake(textField.right - 30, textField.center.y);
        
        [self setImage:[UIImage imageNamed:@"eye.png"] forState:UIControlStateNormal];
        
        [self addTarget:self action:@selector(clickOnEye) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

-(void)clickOnEye{
    UIImage *image = [UIImage imageNamed:@"eye.png"];
    if(self.textField.secureTextEntry) image = [ImageHelper renderImage:image withColor:[UIColor darkGrayColor]];
    [self setImage:image forState:UIControlStateNormal];
    self.textField.secureTextEntry = !self.textField.secureTextEntry;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
